package com.apes.scm.account.res.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * 功能：汇率
 *
 * @author xul
 * @create 2018-02-03 17:56
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = CurrencyRate.CONST_TABLE_NAME)
public class CurrencyRate extends BaseModel {
    public static final String CONST_TABLE_NAME = "res_currency_rate";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "汇率")
    @Comment("汇率编码")
    private long id;

    @Column(name = "name", length = 60)
    @Comment("名称")
    private String name;

    @NotNull
    @ManyToOne(optional = false)
    @JoinColumn(name = "currency_id", referencedColumnName = "id")
    @Comment("币种编码")
    private Currency currency;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    @Comment("公司编码")
    private PartyRole company; //公司

    @Column(name = "rate", nullable = false, columnDefinition = ApesConst.FIELD_ROUND_16_8)
    @Comment("汇率")
    private double rounding; //比率

}
